# app/__init__.py（程序工厂函数）

from flask import Flask
from .extensions import db, redis_client
from .config import load_config
from app.routes import api_blueprint

def create_app(config_filename=None):
    app = Flask(__name__)

    # 加载配置
    config = load_config(config_filename)
    app.config.from_mapping(config)

    # 初始化数据库和Redis
    db.init_app(app)
    redis_client.init_app(app)

    # 注册蓝图
    app.register_blueprint(api_blueprint)

    return app
